[slimtensor] Add SlimTensor class with basic properties and CPU copy operation#16385
Conversation
…operation
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16385
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 5 Unrelated FailuresAs of commit 55d69cd with merge base 9ba1b5d ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…operation
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
ghstack-source-id: 331051343
Pull Request resolved: #16385
This PR needs a
|
…d CPU copy operation"
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
…operation Pull Request resolved: #16385 **Key components:** 1. **`c10/core/Contiguity.h`** - Contiguity checking utility: - `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order) 2. **`core/SlimTensor.h`** - Main SlimTensor class with: - **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset - **Property accessors**: - `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support - `strides()`, `stride(dim)` - get tensor strides with negative indexing support - `dtype()`, `device()`, `device_type()`, `device_index()` - `numel()`, `dim()`, `nbytes()`, `itemsize()` - `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset) - `storage_offset()`, `storage()` - **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()` - **Copy operation**: `copy_(other)` - copies data from another tensor - Fast path: uses memcpy for both-contiguous tensors - Slow path: element-wise copy respecting strides for non-contiguous tensors - **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()` **Curretnt constraints:** - Only CPU device supported - Only Float32 dtype tested - copy_() only supports CPU-to-CPU copy Those contraints will be further improved in the following diffs ghstack-source-id: 331187116 @exported-using-ghexport Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
…d CPU copy operation"
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
…d CPU copy operation"
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
…operation Pull Request resolved: #16385 **Key components:** 1. **`c10/core/Contiguity.h`** - Contiguity checking utility: - `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order) 2. **`core/SlimTensor.h`** - Main SlimTensor class with: - **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset - **Property accessors**: - `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support - `strides()`, `stride(dim)` - get tensor strides with negative indexing support - `dtype()`, `device()`, `device_type()`, `device_index()` - `numel()`, `dim()`, `nbytes()`, `itemsize()` - `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset) - `storage_offset()`, `storage()` - **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()` - **Copy operation**: `copy_(other)` - copies data from another tensor - Fast path: uses memcpy for both-contiguous tensors - Slow path: element-wise copy respecting strides for non-contiguous tensors - **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()` **Curretnt constraints:** - Only CPU device supported - Only Float32 dtype tested - copy_() only supports CPU-to-CPU copy Those contraints will be further improved in the following diffs ghstack-source-id: 332731275 @exported-using-ghexport Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
…d CPU copy operation"
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
…operation Pull Request resolved: #16385 **Key components:** 1. **`c10/core/Contiguity.h`** - Contiguity checking utility: - `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order) 2. **`core/SlimTensor.h`** - Main SlimTensor class with: - **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset - **Property accessors**: - `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support - `strides()`, `stride(dim)` - get tensor strides with negative indexing support - `dtype()`, `device()`, `device_type()`, `device_index()` - `numel()`, `dim()`, `nbytes()`, `itemsize()` - `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset) - `storage_offset()`, `storage()` - **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()` - **Copy operation**: `copy_(other)` - copies data from another tensor - Fast path: uses memcpy for both-contiguous tensors - Slow path: element-wise copy respecting strides for non-contiguous tensors - **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()` **Curretnt constraints:** - Only CPU device supported - Only Float32 dtype tested - copy_() only supports CPU-to-CPU copy Those contraints will be further improved in the following diffs ghstack-source-id: 332735712 @exported-using-ghexport Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
…d CPU copy operation"
**Key components:**
1. **`c10/core/Contiguity.h`** - Contiguity checking utility:
- `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)
2. **`core/SlimTensor.h`** - Main SlimTensor class with:
- **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset
- **Property accessors**:
- `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support
- `strides()`, `stride(dim)` - get tensor strides with negative indexing support
- `dtype()`, `device()`, `device_type()`, `device_index()`
- `numel()`, `dim()`, `nbytes()`, `itemsize()`
- `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset)
- `storage_offset()`, `storage()`
- **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()`
- **Copy operation**: `copy_(other)` - copies data from another tensor
- Fast path: uses memcpy for both-contiguous tensors
- Slow path: element-wise copy respecting strides for non-contiguous tensors
- **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()`
**Curretnt constraints:**
- Only CPU device supported
- Only Float32 dtype tested
- copy_() only supports CPU-to-CPU copy
Those contraints will be further improved in the following diffs
Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
[ghstack-poisoned]
…operation Pull Request resolved: #16385 **Key components:** 1. **`c10/core/Contiguity.h`** - Contiguity checking utility: - `_compute_contiguous<T>()` - computes whether a tensor with given sizes/strides is contiguous in memory (row-major order) 2. **`core/SlimTensor.h`** - Main SlimTensor class with: - **Constructors**: Default (undefined tensor) and full constructor with storage, sizes, strides, dtype, and storage_offset - **Property accessors**: - `sizes()`, `size(dim)` - get tensor dimensions with negative indexing support - `strides()`, `stride(dim)` - get tensor strides with negative indexing support - `dtype()`, `device()`, `device_type()`, `device_index()` - `numel()`, `dim()`, `nbytes()`, `itemsize()` - `data_ptr()` - returns pointer to tensor data (adjusted for storage_offset) - `storage_offset()`, `storage()` - **State queries**: `defined()`, `is_cpu()`, `is_contiguous()`, `is_empty()` - **Copy operation**: `copy_(other)` - copies data from another tensor - Fast path: uses memcpy for both-contiguous tensors - Slow path: element-wise copy respecting strides for non-contiguous tensors - **Setters**: `reset()`, `set_storage()`, `set_sizes_and_strides()` **Curretnt constraints:** - Only CPU device supported - Only Float32 dtype tested - copy_() only supports CPU-to-CPU copy Those contraints will be further improved in the following diffs ghstack-source-id: 332983722 @exported-using-ghexport Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/)
6b137ae
into
gh/gasoonjia/76/base
…operation (#16550) This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #16385 by @Gasoonjia ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/gasoonjia/76/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/gasoonjia/76/head Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/gasoonjia/75/orig Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/gasoonjia/76/orig Differential Revision: [D89750150](https://our.internmc.facebook.com/intern/diff/D89750150/) @diff-train-skip-merge --------- Co-authored-by: gasoonjia <gasoonjia@icloud.com> Co-authored-by: Gasoonjia <gasoonjia@meta.com>
Stack from ghstack (oldest at bottom):
Key components:
c10/core/Contiguity.h- Contiguity checking utility:_compute_contiguous<T>()- computes whether a tensor with given sizes/strides is contiguous in memory (row-major order)core/SlimTensor.h- Main SlimTensor class with:sizes(),size(dim)- get tensor dimensions with negative indexing supportstrides(),stride(dim)- get tensor strides with negative indexing supportdtype(),device(),device_type(),device_index()numel(),dim(),nbytes(),itemsize()data_ptr()- returns pointer to tensor data (adjusted for storage_offset)storage_offset(),storage()defined(),is_cpu(),is_contiguous(),is_empty()copy_(other)- copies data from another tensorreset(),set_storage(),set_sizes_and_strides()Curretnt constraints:
Those contraints will be further improved in the following diffs
Differential Revision: D89750150